package cn.doctor.assistant.pad.ui.zhuye;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.doctor.assistant.pad.R;
import cn.doctor.assistant.pad.api.zhuye.GetNoticeResponse;
import cn.doctor.assistant.pad.api.zhuye.HomeApi;
import cn.doctor.assistant.pad.base.BaseFragment;
import cn.doctor.assistant.pad.base.ResultCallback;

/**
 * Created by jiaolf on 2016/3/21.
 * 主页
 */
public class HomeFragment extends BaseFragment {

    @InjectView(R.id.text_home_ruyuan_count)
    TextView textRuyuanCount;
    @InjectView(R.id.text_home_huifang_count)
    TextView textHuifangCount;
    @InjectView(R.id.text_home_huifang_chengonglv)
    TextView textHuifangChengonglv;
    @InjectView(R.id.text_home_app_jihuo)
    TextView textAppJihuo;
    @InjectView(R.id.text_home_zhuanru_count)
    TextView textZhuanruCount;
    @InjectView(R.id.listview)
    ListView listview;
    @InjectView(R.id.activity_listview_refresh)
    SwipeRefreshLayout swipeRefresh;
    @InjectView(R.id.text_home_notice)
    TextView textHomeNotice;
    @InjectView(R.id.text_notice_detail_btn)
    TextView textNoticeDetailBtn;
    @InjectView(R.id.text_notice_date)
    TextView textNoticeDate;

    private View rootView;
    String noticeText;
    String noticeDate;

    public static HomeFragment newInstance() {
        return new HomeFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        rootView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_home, container, false);
        ButterKnife.inject(this, rootView);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initialize();
    }

    private void initialize() {
        HomeApi.getNotice(new ResultCallback<GetNoticeResponse>() {
            @Override
            public void onSuccess(GetNoticeResponse result) {
                noticeText = result.getContent();
                noticeDate = String.format("%tF", result.getCreate_time().getTime());

                textHomeNotice.setText(noticeText);
                textNoticeDate.setText(noticeDate);
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
